package ca.etsmtl.log430.lab2;

/**
 * Main class for assignment 2 for LOG430, Architecture logicielle.
 * 
 * <pre>
 * <b>Pseudo Code:</b>
 * 
 *   Instantiate Student List, Course List
 *   do until done
 *     Present Menu
 *     if user choice = 1 then List Students
 *     if user choice = 2 then List Courses
 *     if user choice = 3 then List Students
 *     if user choice = 4 then
 *        list students
 *        ask user to select a student
 *        list courses student is registered for
 *     endif
 *     if user choice = 5 then
 *        list students
 *        ask user to select a student
 *        list courses
 *        ask user to select a course
 *        register student for course
 *     endif
 *     if user choice = x then you are done
 *   end do
 * </pre>
 * 
 * @author A.J. Lattanze, CMU
 * @version 1.2, 2011-Feb-02
 */

/*
 * Modification Log
 * **************************************************************************
 * v1.2, 2011-Feb-02, R. Champagne - Various refactorings, javadoc comments.
 * 
 * v1.1, 2002-May-21, R. Champagne - Adapted for use at ETS.
 * 
 * v1.0, 12/29/99, A.J. Lattanze - Original version.
 * **************************************************************************
 */

public class StudentRegistration {

	public static void main(String argv[]) {

		if (argv.length != 2) {

			System.out.println("\n\nIncorrect number of input parameters -"
					+ " correct usage:");

			System.out.println("\nJava StudentRegistration <course file name>"
					+ " <student file name>");

		} else {

			// Declarations:

			boolean Done; // Loop invariant
			char UserChoice; // User's menu choice
			Course MyCourse = null; // A course object
			Student MyStudent = null; // A student object

			// Instantiates a menu object
			Menus Menu = new Menus();

			// Instantiates a display object
			Displays Display = new Displays();

			// The following instantiations create a list of courses and
			// students.
			// The pathname for the file containing course information is passed
			// to the
			// main program on the command line as the first argument (argv[0]).
			// The pathname for the file containing student information is
			// passed to the
			// main program on the command line as the second argument
			// (argv[1]). An example
			// student file and course file is provided as etudiantsLOG.txt and
			// coursLOG.txt

			CourseReader MyCourseList = new CourseReader(argv[0]);
			StudentReader MyStudentList = new StudentReader(argv[1]);

			if ((MyCourseList.getListOfCourses() == null)
					|| (MyStudentList.getListOfStudents() == null)) {

				System.out
						.println("\n\n *** The course list and/or the student"
								+ " list was not initialized ***");

				Done = true;

			} else {

				Done = false;

			} // if

			while (!Done) {

				UserChoice = Menu.mainMenu();

				switch (UserChoice) {

				case '1':

					Display.displayStudentList(MyStudentList
							.getListOfStudents());
					break;

				case '2':

					Display.displayCourseList(MyCourseList.getListOfCourses());
					break;

				case '3':

					Display.displayStudentList(MyStudentList
							.getListOfStudents());
					MyStudent = Menu.pickStudent(MyStudentList
							.getListOfStudents());

					if (MyStudent != null) {

						Display.displayStudentCoursesRegistered(MyStudent);

					} // if

					break;

				case '4':

					Display.displayCourseList(MyCourseList.getListOfCourses());
					MyCourse = Menu.pickCourse(MyCourseList.getListOfCourses());

					if (MyCourse != null) {

						Display.displayStudentsRegistered(MyCourse);

					} // if

					break;

				case '5':

					Display.displayStudentList(MyStudentList
							.getListOfStudents());
					MyStudent = Menu.pickStudent(MyStudentList
							.getListOfStudents());

					if (MyStudent != null) {

						Display.displayCourseList(MyCourseList
								.getListOfCourses());
						MyCourse = Menu.pickCourse(MyCourseList
								.getListOfCourses());

						if (MyCourse != null) {

							MyCourse.register(MyStudent);
							MyStudent.register(MyCourse);

						} // if

					} // if

					break;

				case 'X':

				case 'x':
					Done = true;

				} // switch

			} // while

		} // if

	} // main

} // Class
